package com.ling.sbbyyds.mapper.community;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ling.sbbyyds.entity.community.CommunityPosts;
import com.ling.sbbyyds.interaction.vo.CommunityPostsDetailVo;
import com.ling.sbbyyds.interaction.vo.CommunityPostsVo;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 社区帖子
 */
@Repository
public interface CommunityPostsMapper extends Mapper<CommunityPosts>, BaseMapper<CommunityPosts> {

    /**
     * 获取帖子详情
     *
     * @param postId 帖子id
     * @return
     */
    CommunityPostsDetailVo getPostDetail(Long postId, Long userId);


    /**
     * 获取关注用户发的贴
     *
     * @param start  开始
     * @param end    结束
     * @param userId 用户id
     * @return
     */
    List<CommunityPostsVo> getAttUserRePosts(Integer start, Integer end, Long userId);


    /**
     * 获取关注用户发的贴 总条数
     *
     * @param userId 用户id
     * @return
     */
    List<CommunityPostsVo> getAttUserRePostsCount(Long userId);

    /**
     * 获取帖子喜欢数量（点赞）
     *
     * @param postId 帖子id
     * @return
     */
    @Select("SELECT dian_zan_num AS dianZanNum, posts_id AS postsId FROM sbb_community_posts WHERE posts_id = #{postsId} AND is_del = 0 AND state = 0 ")
    CommunityPosts getPostLikeNum(Long postId);

    /**=
     * 获取帖子收藏数量（点赞）
     *
     * @param postId 帖子id
     * @return
     */
    @Select("SELECT collect_num AS collectNum, posts_id AS postsId FROM sbb_community_posts WHERE posts_id = #{postsId} AND is_del = 0 AND state = 0 ")
    CommunityPosts getPostCollectNum(Long postId);

}
